package com.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {

	private static ThreadPool instance = null;
	private static ExecutorService pool;

	public static synchronized ThreadPool getInstance() {
		if (instance == null) {
			instance = new ThreadPool();
		}
		return instance;
	}

	public synchronized void addToPool(Runnable run) {
		if (pool == null || pool.isShutdown()) {
			int poolSize = SysConfig.getInteger("pool.thread.count");
			if(poolSize <=0){
				poolSize = 50;
			}
			pool = Executors.newFixedThreadPool(poolSize);
		}
		pool.execute(run);
	}
	
	public synchronized void showdown(){
		if(pool != null && !pool.isShutdown()){
			pool.shutdown();
		}
	}
}
